1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33 package com.levelonelabs.aimbot.modules;
34
35 import java.io.IOException;
36 import java.io.InputStream;
37
38 import java.util.ArrayList;
39 import java.util.Properties;
40
41 import java.util.logging.Logger;
42
43 import com.levelonelabs.aim.AIMBuddy;
44
45 import com.levelonelabs.aimbot.AIMBot;
46 import com.levelonelabs.aimbot.BotModule;
47
48
49 /***
50 * Handles requests to control X10 devices using Heyu and CM11A. Heyu runs on
51 * Linux/Unix and is written by Daniel B. Suthers. Heyu is available for free
52 * at http://heyu.tanj.com. Daniel requests that NO mirrors of his Heyu source
53 * code be created.
54 *
55 * HeyuModule officially supports Heyu version 1.35. HeyuModule REQUIRES a
56 * WORKING INSTALLATION of Heyu on the same physical machine (i.e. you must be
57 * running the jaimbot on Linux/Unix with a CM11A attached and Heyu installed,
58 * running and working).
59 *
60 * Please see the Heyu FAQ at http://heyu.tanj.com for details about X10 and
61 * the CM11A. The CM11A is available from http://www.x10.com and other sources
62 * for under $50. Bundled deals that include X10 modules for the CM11A to
63 * control can often be purchased at that price (a substantial discount).
64 * Please note: The author is NOT trying to generate sales for X10, just simply
65 * stating how you can get started using this module.
66 *
67 * CM11A and X10 may be Registered Trademarks of X10 Corp. (http://www.x10.com)
68 *
69 * The author of this software is not affiliated with X10 Corp.
70 *
71 * @author David Nelson (david@david-nelson.com)
72 *
73 * @created November 22, 2003
74 */
75 public class HeyuModule extends BotModule {
76 private static ArrayList services;
77 private static Logger logger = Logger.getLogger(HeyuModule.class.getName());
78 private static String requiredRole = AIMBot.ROLE_ADMINISTRATOR;
79 private static String heyuPath = "/usr/local/bin/heyu";
80 private static String successMessage = "";
81 private String modulesText = "";
82 private boolean allowHelp = false;
83
84 /***
85 * Initialize the service commands.
86 */
87 static {
88 services = new ArrayList();
89 services.add("turn");
90 services.add("heyu");
91 }
92
93
94 public ArrayList getServices() {
95 return services;
96 }
97
98
99 public String help() {
100 String helpText = "";
101 StringBuffer sb = new StringBuffer();
102
103 if (allowHelp) {
104 sb.append("<B>turn</B> (executes Heyu commands)\n");
105 sb.append("\n<b>EXAMPLE: turn office on</b>\n");
106 sb.append("<B>heyu</B> (lists admin supplied module text)\n");
107 helpText = sb.toString();
108 }
109 return helpText;
110 }
111
112
113 public String getModules() {
114 return modulesText;
115 }
116
117
118 public void performService(AIMBuddy buddy, String query) {
119 if (buddy.hasRole(requiredRole)) {
120 if (query.toLowerCase().startsWith("turn")) {
121 try {
122 Runtime.getRuntime().exec(heyuPath + " " + query.toLowerCase());
123 logger.finest(buddy.getName() + " performed: " + query.toLowerCase());
124 if (successMessage != null && successMessage.trim().length() > 0) {
125 super.sendMessage(buddy, successMessage);
126 }
127 } catch (IOException ioe) {
128 super.sendMessage(buddy, "Error processing command: " + ioe.getMessage());
129 logger.severe("Error processing command: " + ioe.getMessage());
130 }
131 } else if (query.toLowerCase().startsWith("heyu")) {
132 super.sendMessage(buddy, getModules());
133 }
134 }
135 }
136
137
138 public String getName() {
139 return "Heyu Module";
140 }
141
142
143 public HeyuModule(AIMBot bot) {
144 super(bot);
145
146 Properties props = new Properties();
147 try {
148 InputStream is = ClassLoader.getSystemResourceAsStream("HeyuModule.properties");
149 props.load(is);
150 requiredRole = props.getProperty("requiredRole", requiredRole);
151 heyuPath = props.getProperty("heyuPath", heyuPath);
152 successMessage = props.getProperty("successMessage", successMessage);
153 String helpAllowed = props.getProperty("allowHelp");
154 if (helpAllowed != null) {
155 helpAllowed = helpAllowed.trim().toLowerCase();
156 } else {
157 helpAllowed = "false";
158 }
159 allowHelp = (helpAllowed.equals("true"));
160 int i = 0;
161 String module = props.getProperty("modules" + i);
162 while (module != null) {
163 modulesText = modulesText + module + "\n";
164 i++;
165 module = props.getProperty("modules" + i);
166 }
167 } catch (Exception e) {
168 logger.info("Error Reading HeyuModule.properties: " + e.getMessage());
169 }
170 }
171 }